//
//  ViewController.m
//  NoteBook
//
//  Created by 云荒 on 15/11/11.
//  Copyright © 2015年 北落师门. All rights reserved.
//

#import "RootViewController.h"

#import "TimeLineViewController.h"
#import "PastTimeViewController.h"
#import "AddDiaryViewController.h"
#import "ImportViewController.h"
#import "OptionViewController.h"


@interface  RootViewController()<UITabBarControllerDelegate>

@property (nonatomic,strong)UIButton *addButton;

@end




@implementation RootViewController




- (instancetype)init
{
    self = [super init];
    if (self) {
//        self.tabBar.alpha = 0.7;
        
        self.delegate = self;
        
        UIImage *btnImage = [UIImage imageNamed:@"3"];
        

        _addButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _addButton.frame = CGRectMake(0, 0, btnImage.size.width * 1.5, btnImage.size.height * 1.5);
        [_addButton setBackgroundImage:btnImage forState:UIControlStateNormal];
        [_addButton setBackgroundImage:btnImage forState:UIControlStateSelected];
        _addButton.adjustsImageWhenHighlighted = NO;
        _addButton.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleTopMargin;

        CGFloat heightDifference = btnImage.size.height  - self.tabBar.frame.size.height;
        CGPoint buttonCenter = self.tabBar.center;
        buttonCenter.y -= heightDifference;
        
        
        _addButton.center = CGPointMake(self.tabBar.center.x, self.view.window.frame.size.height + 2);
        [_addButton addTarget:self action:@selector(add) forControlEvents:UIControlEventTouchUpInside];
        [self.tabBar addSubview:_addButton];

    }
    return self;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
//    self.tabBar.tintColor = [UIColor blueColor];

    // Do any additional setup after loading the view, typically from a nib.
}

- (void)add
{
    self.selectedIndex = 2;
    _addButton.selected = YES;
    
}

-(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
    if (self.selectedIndex == 2) {
        _addButton.selected = YES;
    }else
    {
        _addButton.selected = NO;
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
